package com.xunqi.ad.form;

import com.xunqi.ad.entity.Creative;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @Description:
 * @Created with IntelliJ IDEA.
 * @author: 夏沫止水
 * @createTime: 2020-04-30 20:55
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreativeForm {

    @NotEmpty(message = "创意名称不能为空")
    private String name;

    @NotNull(message = "物料类型不能为空")
    private Integer type;

    @NotNull(message = "物料子类型不能为空")
    private Integer materialType;

    @NotNull(message = "高度不能为空")
    private Integer height;

    @NotNull(message = "宽度不能为空")
    private Integer width;

    @NotNull(message = "物料大小不能为空")
    private Long size;

    @NotNull(message = "持续时长不能为空")
    private Integer duration;

    @NotNull(message = "所属用户不能为空")
    private Long userId;

    @NotEmpty(message = "物料地址不能为空")
    private String url;

    /**
     * 将Creative对象转换为实体类
     * @return
     */
    public Creative convertToEntity() {

        Creative creative = new Creative();
        creative.setName(name);
        creative.setType(type);
        creative.setMaterialType(materialType);
        creative.setHeight(height);
        creative.setWidth(width);
        creative.setSize(size);
        creative.setDuration(duration);
        creative.setAuditStatus(1);
        creative.setUserId(userId);
        creative.setUrl(url);
        creative.setCreateTime(new Date());
        creative.setUpdateTime(creative.getCreateTime());

        return creative;
    }

}
